<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>抖好货</title>
    <link rel="stylesheet" type="text/css" href="../../css/aui.css" />
    <link rel="stylesheet" href="https://cdn.bootcss.com/Swiper/4.0.6/css/swiper.min.css">
    <style media="screen">
        #app {
            width: 100%;
            overflow: hidden;
            background: linear-gradient(266deg, #7D0DFC, #D116FD);
        }

        header {
            width: 100%;
            height: 44px;
        }

        .title {
            width: 100%;
            padding: 0 140px;
            text-align: center;
            white-space: nowrap;
            line-height: 44px;
            overflow: hidden;
            text-overflow: ellipsis;
            z-index: 2;
            color: #fff;
            font-size: 17px;
            display: flex;
        }

        .title img {
            display: inline-block;
            width: 17px;
            height: 20px;
            margin-top: 12.5px;
        }

        .title label {
            line-height: 48px;
            margin-left: 5px;
        }

        header span {
            display: block;
            width: 44px;
            height: 44px;
            background: url(../../image/white_back.png) no-repeat;
            background-size: 22px 22px;
            background-position: center;
            position: absolute;
        }

        .swiper-slide {
            width: auto!important;
            position: relative;
        }

        .swiper-slide>span {
            display: block;
            color: #fff;
        }

        .swiper-slide span:first-child {
            height: 30px;
            padding: 0 5px;
            line-height: 30px;
            font-family: "微软雅黑";
            color: #fff;
            font-size: 15px;
        }

        .swiper-slide span.line {
            width: 50%;
            height: 1px;
            background-color: #fff;
            position: absolute;
            bottom: 0px;
            left: 50%;
            margin-left: -25%;
        }

        .topmenu {
            height: 30px;
            background: linear-gradient(266deg, #7D0DFC, #D116FD);
            padding: 0 5px;
            line-height: 30px;
            font-family: "微软雅黑";
        }
    </style>
</head>

<body>
    <div id="app">
        <header id="header">
            <span tapmode @click="closeWin()"></span>
            <div class="title"><img src="../../image/dhh.png" alt=""><label>抖好货</label></div>
        </header>
        <div class="topmenu">
            <div class="swiper-container">
                <div class="swiper-wrapper">
                    <div class="swiper-slide" v-for='(item,index) in navlist' tapmode @click="change(index)">
                        <span class="text">{{item.cname}}</span>
                        <span :class="{'line':isActive==index}"></span>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/vue.js"></script>
<script type="text/javascript" src="../../script/cling.js"></script>
<script src="../../script/swiper.js"></script>
<script type="text/javascript">
    apiready = function() {
        var header = $api.byId('app');
        var headerH = $api.fixStatusBar(header);
        // api.openFrame({
        //     name: 'package_mail_frame',
        //     url: './package_mail_frame.html',
        //     rect: {
        //         marginTop: headerH,
        //         marginBottom: api.safeArea.bottom, // main页面距离win底部的高度
        //         w: 'auto'
        //     },
        //     bounces: true,
        //     bgColor: '#FAF9F9',
        //     vScrollBarEnabled: true,
        //     hScrollBarEnabled: true
        // });
        vm.getcate()

    }
    var vm = new Vue({
        el: '#app',
        data: {
            isActive: 0,
            navlist: []
        },
        methods: {
            getcate: function() {
                api.ajax({
                    url: cl.apiServer + 'category/getCategoryList',
                    method: 'post',
                    headers: {
                        'Content-Type': 'application/json;charset=utf-8',
                        token:cl.userToken
                    },
                    data: {
                        body: {
                            parentId: 0,
                            ctype: 4,
                            version:cl.deviceInfo().appVersion,
                            mobileInfo:cl.systemType()
                        }
                    }
                }, function(ret, err) {
                    console.log(JSON.stringify(ret));
                    if (ret) {
                        if (ret.code == 0) {
                            vm.navlist = ret.data;
                            setTimeout(function() {
                                var swiper = new Swiper('.swiper-container', {
                                    spaceBetween: 20,
                                    slidesPerView: 'auto',
                                    freeMode: true
                                }, 1000);
                            });
                            var header = $api.byId('app');
                            var headerH = $api.fixStatusBar(header);
                            var frames = [];
                            for (var i = 0; i < vm.navlist.length; i++) {
                                frames.push({
                                    name: 'shake_goods_frame' + i,
                                    url: './shake_goods_frame.html',
                                    bounces: true,
                                    bgColor: "#FAF9F9",
                                    pageParam: {
                                        id: vm.navlist[i].cid
                                    }
                                })
                            }
                            api.openFrameGroup({
                                name: 'shake_goodsGroup',
                                background: '#FAF9F9',
                                scrollEnabled: false,
                                rect: {
                                    x: 0,
                                    y: headerH,
                                    w: 'auto',
                                    h: 'auto'
                                },
                                index: 0,
                                preload:1,
                                frames: frames
                            }, function(ret, err) {
                                if (ret) {
                                    // alert(JSON.stringify(ret));
                                }
                            });
                        }
                    }
                });
            },
            change: function(index) {
              console.log(index);
                vm.isActive = index;
                api.setFrameGroupIndex({
                    name: 'shake_goodsGroup',
                    scroll: true,
                    index: index
                });
            },
            closeWin: function() {
                cl.closeWin({
                    name: 'shake_goods'
                })
            }
        }
    });
</script>

</html>
